<!--<?php
print <<<EOT
-->
<base target="_self">
<script language="javascript">
var path = '$very[url]/$very[attachdir]';
var _img = null;
var inputname = '$inputname';
var inputtype = '$inputtype';

function showpic(filepath){
	var preview = document.getElementById('preview');
	document.getElementById('picture').innerHTML="正在加载图片，请稍侯...";
	_img = new Image();
	_img.src = path+"/"+filepath;
	preview.style.display='';
	checkLoadFinished(1);			
}

function insertImg(aid,filename){
	var imgsrc = path+"/"+filename;
	if(window.dialogArguments){
		var win = window.dialogArguments;
	}else{
		var win = window.opener;
	}
	//var input = window.opener.document.getElementsByName(inputname);
	if(inputtype=='editor'){
		win.document.getElementById(inputname).value=imgsrc;
		//win.parent.dialogArguments.document.getElementById('aid').value+=','+aid;
	}else if(inputtype=='input'){
		win.document.getElementById(inputname).value=imgsrc;
		win.document.getElementById('aid').value=','+aid;
	}
	window.close();

}

function hidePreview(){
	document.getElementById('preview').style.display='none';
}

function checkLoadFinished(count) {
	if (count > 1000) { document.getElementById('picture').innerHTML = '发生错误，加载图片超时'; return; }
	var state = '';
	if (document.all) state = _img.readyState;
	else state = _img.complete ? 'complete' : '';
	if(state!='complete') { window.setTimeout("checkLoadFinished(" + (count + 1) + ")",50); return; }
	var MaxW = 300; var MaxH = 200;
    var dW=_img.width; var dH=_img.height;
    if(dW>MaxW || dH>MaxH) {  a=dW/MaxW; b=dH/MaxH;if(b>a){ a=b; } dW=dW/a; dH=dH/a; }
    if(dW > 0 && dH > 0) { _img.width=dW; _img.height=dH; }

	var picture = document.getElementById("picture");
	var childs = picture.childNodes; for (var i = 0; i < childs.length; ++i) picture.removeChild(childs[i]);
	_img.style.border="#E3E3E3 5px solid";
	picture.appendChild(_img);
	document.getElementById('loading').style.display="none";
}

function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
{
	switch ( errorNumber )
	{
		case 0 :	// No errors
			alert( 'Your file has been successfully uploaded' ) ;
			break ;
		case 1 :	// Custom error
			alert( customMsg ) ;
			return ;
		case 101 :	// Custom warning
			alert( customMsg ) ;
			break ;
		case 201 :
			alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
			break ;
		case 202 :
			alert( 'Invalid file type' ) ;
			return ;
		case 203 :
			alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
			return ;
		default :
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
			return ;
	}
	document.getElementById('reload').click();
	GetE('frmUpload').reset() ;
}
</script>
<body onkeydown="if (event.keyCode==116){reload.click();}">
<a id="reload" href="$basename&action=addimage&inputtype=$inputtype&inputname=$inputname" style="display:none">reload...</a>
<div id="loading" style="color:white;background-color:blue;position:absolute;padding:5px;display:none;
	top:250px; left:300px;">
	<label id="DownloadInfo" style="display:block;color:#FFF;">正在加载图片，请稍候...</label>
</div>
<div id="preview" style="background-color:#FFFFFF; position:absolute; right:5px; top:5px; width:400px; display:none" class="t">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr class="head">
			<td><div style="float:right"><img src="images/admin/close.gif" onClick="hidePreview();" style="cursor:pointer"></div>
				图片预览区域</td>
		</tr>
		<tr>
			<td><div id='picture' style="padding:10px;text-align:center; width:100%"> </div></td>
		</tr>
	</table>
</div>
<div class="t">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr class="head">
			<td colspan="5">附件管理
				<form action="$basename" method="post" name="upload" target="uploadFrame" enctype="multipart/form-data">
					上传
					<input name="file" type="file" class="input" />
					描述：
					<input type="text" name="fileintro1" class="input" />
					<input name="inputname" type="hidden" id="inputname" value="$inputname" />
					<input name="inputtype" type="hidden" id="inputtype" value="$inputtype" />
					<input name="action" type="hidden" id="action" value="upload" />
					<input type="submit" name="Submit" value=" 上传 " class="btn" />
				</form></td>
		</tr>
		<tr class="tr2">
			<td>文件名</td>
			<td>描述</td>
			<td>插入</td>
			<td>文件大小</td>
			<td>上传时间</td>
		</tr>
<!--
EOT;
$imgext = array('gif','jpg','jpeg','png');
$mediaext = array('swf','wma','mp3','wmv','avi','asx','mov','rm','rmvb','mid');
foreach($files as $file){
if(in_array(strtolower($file[type]),$imgext)||in_array(strtolower($file[type]),$mediaext)){
$addimg="<img src=\"images/admin/insert.gif\" style=\"cursor:pointer;\" align=\"absmiddle\" onClick=\"insertImg($file[aid],'".$file[filepath]."');\" alt=\"插入此文件\">";
}else{
$addimg='';
}
print <<<EOT
-->
		<tr class="tr3">
			<td><img src="$file[icon]" width="16" height="16" hspace="5" align="absmiddle" /> <a href="$file[url]" >$file[filename]</a> </td>
			<td>$file[fileintro]&nbsp;</td>
			<td>$addimg</td>
			<td>$file[filesize]<br /></td>
			<td>$file[uploadtime]<br />
				<a href="$basename&action=del&path=$path&file=$file[name]"></a></td>
		</tr>
<!--
EOT;
}print <<<EOT
-->
		<tr>
			<td colspan="5">$pages</td>
		</tr>
	</table>
</div>
<iframe name="uploadFrame" width="0" style="display:none"></iframe>
<!--
EOT;
?>-->
